<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>Tk_CreateEventHandler manual page - Library Procedures</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tk C API</a> <small>&gt;</small> EventHndlr</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<H3><A NAME="M2">NAME</A></H3>
Tk_CreateEventHandler, Tk_DeleteEventHandler &mdash; associate procedure callback with an X event
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>#include &lt;tk.h&gt;</B><BR>
<B>Tk_CreateEventHandler</B>(<I>tkwin, mask, proc, clientData</I>)<BR>
<B>Tk_DeleteEventHandler</B>(<I>tkwin, mask, proc, clientData</I>)<BR>
<H3><A NAME="M4">ARGUMENTS</A></H3>
<DL class="arguments">
<DT><A HREF="../TkLib/WindowId.htm">Tk_Window</A> <B>tkwin</B> (in)<DD>
Token for window in which events may occur.
<P><DT>unsigned long <B>mask</B> (in)<DD>
Bit-mask of events (such as <B>ButtonPressMask</B>)
for which <I>proc</I> should be called.
<P><DT>Tk_EventProc <B>*proc</B> (in)<DD>
Procedure to invoke whenever an event in <I>mask</I> occurs
in the window given by <I>tkwin</I>.
<P><DT>ClientData <B>clientData</B> (in)<DD>
Arbitrary one-word value to pass to <I>proc</I>.
<P></DL>
<H3><A NAME="M5">DESCRIPTION</A></H3>
<B>Tk_CreateEventHandler</B> arranges for <I>proc</I> to be
invoked in the future whenever one of the event types specified
by <I>mask</I> occurs in the window specified by <I>tkwin</I>.
The callback to <I>proc</I> will be made by <B><A HREF="../TkLib/HandleEvent.htm">Tk_HandleEvent</A></B>;
this mechanism only works in programs that dispatch events
through <B><A HREF="../TkLib/HandleEvent.htm">Tk_HandleEvent</A></B> (or through other Tk procedures that
call <B><A HREF="../TkLib/HandleEvent.htm">Tk_HandleEvent</A></B>, such as <B><A HREF="../TclLib/DoOneEvent.htm">Tcl_DoOneEvent</A></B> or
<B><A HREF="../TkLib/MainLoop.htm">Tk_MainLoop</A></B>).
<P>
<I>Proc</I> should have arguments and result that match the
type <B>Tk_EventProc</B>:
<PRE>typedef void <B>Tk_EventProc</B>(
        ClientData <I>clientData</I>,
        XEvent *<I>eventPtr</I>);</PRE>
The <I>clientData</I> parameter to <I>proc</I> is a copy of the <I>clientData</I>
argument given to <B>Tk_CreateEventHandler</B> when the callback
was created.  Typically, <I>clientData</I> points to a data
structure containing application-specific information about
the window in which the event occurred.  <I>EventPtr</I> is
a pointer to the X event, which will be one of the ones
specified in the <I>mask</I> argument to <B>Tk_CreateEventHandler</B>.
<P>
<B>Tk_DeleteEventHandler</B> may be called to delete a
previously-created event handler:  it deletes the first handler
it finds that is associated with <I>tkwin</I> and matches the
<I>mask</I>, <I>proc</I>, and <I>clientData</I> arguments.  If
no such handler exists, then <B><A HREF="../TkLib/HandleEvent.htm">Tk_HandleEvent</A></B> returns
without doing anything.  Although Tk supports it, it's probably
a bad idea to have more than one callback with the same <I>mask</I>,
<I>proc</I>, and <I>clientData</I> arguments.
When a window is deleted all of its handlers will be deleted
automatically;  in this case there is no need to call
<B>Tk_DeleteEventHandler</B>.
<P>
If multiple handlers are declared for the same type of X event
on the same window, then the handlers will be invoked in the
order they were created.
<H3><A NAME="M6">KEYWORDS</A></H3>
<A href="../Keywords/B.htm#bind">bind</A>, <A href="../Keywords/C.htm#callback">callback</A>, <A href="../Keywords/E.htm#event">event</A>, <A href="../Keywords/H.htm#handler">handler</A>
<div class="copy">Copyright &copy; 1990 The Regents of the University of California.
<BR>Copyright &copy; 1994-1996 Sun Microsystems, Inc.
</div>
</BODY></HTML>
